#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define ONE (1 << 0)
#define TWO (1 << 1)
#define THREE (1 << 2)
#define FOUR (1 << 3)

//void show(int flag)
//{
//  if (flag & ONE) printf("function1\n");
//  if (flag & TWO) printf("function2\n");
//  if (flag & THREE) printf("function3\n");
//  if (flag & FOUR) printf("function4\n");
//}

int main()
{
  close(0);
  int fd1 = open("log1.txt", O_WRONLY | O_CREAT, 0666);
  printf("fd1: %d\n", fd1);
  int fd2 = open("log2.txt", O_WRONLY | O_CREAT, 0666);
  printf("fd2: %d\n", fd2);
  int fd3 = open("log3.txt", O_WRONLY | O_CREAT, 0666);
  printf("fd3: %d\n", fd3);
//  printf("stdin->fd: %d\n", stdin->_fileno);
//  printf("stdout->fd: %d\n", stdout->_fileno);
//  printf("stderr->fd: %d\n", stderr->_fileno);
//
  //char buffer[1024];
  //read(0, buffer, sizeof(buffer));
  //printf("%s", buffer);

  //int fd1 = open("log1.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
  //printf("fd: %d\n", fd1);
  // const char* mesg = "bbb";
 // write(fd, mesg, strlen(mesg));
 // close(fd1);
  //int fd = open("log.txt", O_WRONLY | O_CREAT, 0666);
  //if (fd < 0) printf("open error\n");

//  show(ONE); // 1
//  printf("\n");
//  show(ONE | TWO); // 1 && 2
//  printf("\n");
//  show(ONE | TWO | THREE); // 1 && 2 && 3
//  printf("\n");
//  show(ONE | TWO | THREE | FOUR); // 1 && 2 && 3 && 4

  //const char* mesg = "abcd\n";
  //fwrite(mesg, strlen(mesg), 1, stdout);
  //fprintf(stdout,"%s", mesg);
  //fprintf(stderr,"%s", mesg);
  //FILE* fp = fopen("log.txt", "wa");
  //const char* mesg = "aaabbbccc";
  //
  //printf("pid: %d\n", getpid());
  //while (1)
  //{
  //  fwrite(mesg, strlen(mesg), 1, fp);  
  //}

  //fclose(fp);

  return 0;
}
